package com.yanxinim.cn.ui;import android.Manifest;import android.app.Activity;import android.app.ActivityManager;import android.app.NotificationManager;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.content.IntentFilter;import android.content.res.ColorStateList;import android.graphics.Bitmap;import android.graphics.drawable.Drawable;import android.os.Bundle;import android.os.Handler;import android.os.IBinder;import android.os.Looper;import android.os.Message;import android.os.Process;import android.text.TextUtils;import android.util.Log;import android.view.KeyEvent;import android.view.View;import android.view.inputmethod.InputMethodManager;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.TextView;import android.widget.Toast;import androidx.core.content.ContextCompat;import androidx.core.graphics.drawable.DrawableCompat;import androidx.fragment.app.Fragment;import androidx.fragment.app.FragmentManager;import androidx.fragment.app.FragmentTransaction;import com.alibaba.fastjson.JSON;import com.alibaba.fastjson.JSONObject;import com.bumptech.glide.Glide;import com.coloros.mcssdk.PushManager;import com.example.qrcode.Constant;import com.example.qrcode.ScannerActivity;import com.fanjun.keeplive.KeepLive;import com.fanjun.keeplive.config.KeepLiveService;import com.google.android.gms.common.ConnectionResult;import com.google.android.gms.common.GoogleApiAvailability;import com.yanxinim.cn.AppConfig;import com.yanxinim.cn.AppConstant;import com.yanxinim.cn.MyApplication;import com.yanxinim.cn.R;import com.yanxinim.cn.Reporter;import com.yanxinim.cn.bean.Contact;import com.yanxinim.cn.bean.Contacts;import com.yanxinim.cn.bean.Friend;import com.yanxinim.cn.bean.UploadingFile;import com.yanxinim.cn.bean.User;import com.yanxinim.cn.bean.collection.Collectiion;import com.yanxinim.cn.bean.event.EventCreateGroupFriend;import com.yanxinim.cn.bean.event.EventQRCodeReady;import com.yanxinim.cn.bean.event.EventSendVerifyMsg;import com.yanxinim.cn.bean.event.MessageContactEvent;import com.yanxinim.cn.bean.event.MessageEventBG;import com.yanxinim.cn.bean.event.MessageEventHongdian;import com.yanxinim.cn.bean.event.MessageLogin;import com.yanxinim.cn.bean.event.MessageSendChat;import com.yanxinim.cn.bean.message.ChatMessage;import com.yanxinim.cn.bean.message.MucRoom;import com.yanxinim.cn.bean.message.XmppMessage;import com.yanxinim.cn.broadcast.MsgBroadcast;import com.yanxinim.cn.broadcast.MucgroupUpdateUtil;import com.yanxinim.cn.broadcast.OtherBroadcast;import com.yanxinim.cn.broadcast.TimeChangeReceiver;import com.yanxinim.cn.broadcast.UpdateUnReadReceiver;import com.yanxinim.cn.broadcast.UserLogInOutReceiver;import com.yanxinim.cn.call.AudioOrVideoController;import com.yanxinim.cn.call.CallConstants;import com.yanxinim.cn.call.Jitsi_connecting_second;import com.yanxinim.cn.call.MessageEventCancelOrHangUp;import com.yanxinim.cn.call.MessageEventInitiateMeeting;import com.yanxinim.cn.db.dao.ChatMessageDao;import com.yanxinim.cn.db.dao.ContactDao;import com.yanxinim.cn.db.dao.FriendDao;import com.yanxinim.cn.db.dao.MyZanDao;import com.yanxinim.cn.db.dao.NewFriendDao;import com.yanxinim.cn.db.dao.OnCompleteListener2;import com.yanxinim.cn.db.dao.UploadingFileDao;import com.yanxinim.cn.db.dao.UserDao;import com.yanxinim.cn.db.dao.login.MachineDao;import com.yanxinim.cn.downloader.UpdateManger;import com.yanxinim.cn.fragment.DiscoverFragment;import com.yanxinim.cn.fragment.FriendFragment;import com.yanxinim.cn.fragment.MeFragment;import com.yanxinim.cn.fragment.MessageFragment;import com.yanxinim.cn.fragment.NewsFragment;import com.yanxinim.cn.fragment.SquareFragment;import com.yanxinim.cn.helper.DialogHelper;import com.yanxinim.cn.helper.LoginHelper;import com.yanxinim.cn.helper.LoginSecureHelper;import com.yanxinim.cn.helper.PrivacySettingHelper;import com.yanxinim.cn.map.MapHelper;import com.yanxinim.cn.pay.PaymentReceiptMoneyActivity;import com.yanxinim.cn.pay.ReceiptPayMoneyActivity;import com.yanxinim.cn.socket.SocketException;import com.yanxinim.cn.sp.UserSp;import com.yanxinim.cn.store.bean.UserType;import com.yanxinim.cn.ui.backup.ReceiveChatHistoryActivity;import com.yanxinim.cn.ui.base.BaseActivity;import com.yanxinim.cn.ui.base.CoreManager;import com.yanxinim.cn.ui.lock.DeviceLockActivity;import com.yanxinim.cn.ui.lock.DeviceLockHelper;import com.yanxinim.cn.ui.login.WebLoginActivity;import com.yanxinim.cn.ui.message.MucChatActivity;import com.yanxinim.cn.ui.other.BasicInfoActivity;import com.yanxinim.cn.ui.other.QRcodeActivity;import com.yanxinim.cn.ui.tool.WebViewActivity;import com.yanxinim.cn.util.AppUtils;import com.yanxinim.cn.util.AsyncUtils;import com.yanxinim.cn.util.Constants;import com.yanxinim.cn.util.ContactsUtil;import com.yanxinim.cn.util.DeviceInfoUtil;import com.yanxinim.cn.util.DisplayUtil;import com.yanxinim.cn.util.FileUtil;import com.yanxinim.cn.util.HttpUtil;import com.yanxinim.cn.util.JsonTool;import com.yanxinim.cn.util.JsonUtils;import com.yanxinim.cn.util.PermissionUtil;import com.yanxinim.cn.util.PreferenceUtils;import com.yanxinim.cn.util.ScreenUtil;import com.yanxinim.cn.util.SkinUtils;import com.yanxinim.cn.util.TimeUtils;import com.yanxinim.cn.util.ToastUtil;import com.yanxinim.cn.util.UiUtils;import com.yanxinim.cn.util.log.LogUtils;import com.yanxinim.cn.view.PermissionExplainDialog;import com.yanxinim.cn.view.SelectionFrame;import com.yanxinim.cn.view.VerifyDialog;import com.yanxinim.cn.xmpp.CoreService;import com.yanxinim.cn.xmpp.ListenerManager;import com.yanxinim.cn.xmpp.helloDemon.FirebaseMessageService;import com.yanxinim.cn.xmpp.helloDemon.HuaweiClient;import com.yanxinim.cn.xmpp.helloDemon.MeizuPushMsgReceiver;import com.yanxinim.cn.xmpp.helloDemon.OppoPushMessageService;import com.yanxinim.cn.xmpp.helloDemon.VivoPushMessageReceiver;import com.yanxinim.cn.xmpp.listener.ChatMessageListener;import com.xiaomi.mipush.sdk.MiPushClient;import com.xuan.xuanhttplibrary.okhttp.HttpUtils;import com.xuan.xuanhttplibrary.okhttp.callback.BaseCallback;import com.xuan.xuanhttplibrary.okhttp.callback.ListCallback;import com.xuan.xuanhttplibrary.okhttp.result.ArrayResult;import com.xuan.xuanhttplibrary.okhttp.result.ObjectResult;import com.xuan.xuanhttplibrary.okhttp.result.Result;import java.io.ByteArrayOutputStream;import java.io.IOException;import java.util.ArrayList;import java.util.Arrays;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.UUID;import androidx.multidex.BuildConfig;import cn.jpush.android.api.JPushInterface;import cn.jpush.android.service.JPushMessageReceiver;import de.greenrobot.event.EventBus;import de.greenrobot.event.Subscribe;import de.greenrobot.event.ThreadMode;import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;import me.leolin.shortcutbadger.ShortcutBadger;import okhttp3.Call;import okhttp3.Callback;import okhttp3.Response;import static android.os.Process.killProcess;/** * 主界面 */public class MainActivity extends BaseActivity implements PermissionUtil.OnRequestPermissionsResultCallbacks {    // 小米推送//    xiaomiAppId = '2882303761518984926' // 小米推送配置的appId,//    xiaomiAppKey = '5871898498926' // 小米推送配置的appKey,    public static final String APP_ID = "2882303761518984926";    public static final String APP_KEY = "5871898498926";    // 是否重新走initView方法    // 当切换语言、修改皮肤之后，将该状态置为true    public static boolean isInitView = false;    /**     * 更新我的群组     */    Handler mHandler = new Handler();    private UpdateUnReadReceiver mUpdateUnReadReceiver = null;    private UserLogInOutReceiver mUserLogInOutReceiver = null;    private TimeChangeReceiver timeChangeReceiver = null;    private ActivityManager mActivityManager;    // ╔═══════════════════════════════界面组件══════════════════════════════╗    // ╚═══════════════════════════════界面组件══════════════════════════════╝    private int mLastFragmentId;// 当前界面    private RadioGroup mRadioGroup;//    private RadioButton mRbTab1, mRbTab2, mRbTab3, mRbTab4, mRbTab5;    private RadioButton mRbTab1, mRbTab2, mRbTab3, mRbTab4;    private TextView mTvMessageNum;// 显示消息界面未读数量    private TextView mTvNewFriendNum;// 显示通讯录消息未读数量    private TextView mTvCircleNum;// 显示朋友圈未读数量    private int numMessage = 0;// 当前未读消息数量    private int numCircle = 0; // 当前朋友圈未读数量    private String mUserId;// 当前登陆的 UserID    private My_BroadcastReceiver my_broadcastReceiver;    private int mCurrtTabId;    private boolean isCreate;    /**     * 在其他设备登录了，挤下线     */    private boolean isConflict;    private Handler handler = new Handler(Looper.myLooper()){        @Override        public void handleMessage(Message msg) {            super.handleMessage(msg);            initMap();//            getAppInfo();            setOnLine("1");        }    };    private int keyCode;    private KeyEvent event;    public MainActivity() {        noLoginRequired();    }    public static void start(Context ctx) {        Intent intent = new Intent(ctx, MainActivity.class);        ctx.startActivity(intent);    }    /**     * 发起二维码扫描，     * 仅供MainActivity下属Fragment调用，     */    public static void requestQrCodeScan(Activity ctx) {        int size = ScreenUtil.getScreenWidth(MyApplication.getContext()) / 16 * 9;        // 生成底部自己的二维码bitmap        QRcodeActivity.getSelfQrCodeBitmap(size,                CoreManager.requireSelf(ctx).getUserId(),                CoreManager.requireSelf(ctx).getNickName());    }    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        // 自动解锁屏幕 | 锁屏也可显示 | Activity启动时点亮屏幕 | 保持屏幕常亮/*        getWindow().addFlags(                WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD                        | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED                        | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON                        | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);*/        setContentView(R.layout.activity_main);        // 启动保活        if (PrivacySettingHelper.getPrivacySettings(this).getIsKeepalive() == 1) {            initKeepLive();        }        initLog();        mUserId = coreManager.getSelf().getUserId();        initView();// 初始化控件        initBroadcast();// 初始化广播        initDatas();// 初始化一些数据        // 初始化音视频Control        AudioOrVideoController.init(mContext, coreManager);        AsyncUtils.doAsync(this, mainActivityAsyncContext -> {            // 获取app关闭之前还在上传的消息，将他们的发送状态置为失败            List<UploadingFile> uploadingFiles = UploadingFileDao.getInstance().getAllUploadingFiles(coreManager.getSelf().getUserId());            for (int i = uploadingFiles.size() - 1; i >= 0; i--) {                ChatMessageDao.getInstance().updateMessageState(coreManager.getSelf().getUserId(), uploadingFiles.get(i).getToUserId(),                        uploadingFiles.get(i).getMsgId(), ChatMessageListener.MESSAGE_SEND_FAILED);            }        });        UpdateManger.checkUpdate(this, coreManager.getConfig().androidAppUrl, coreManager.getConfig().androidVersion);        EventBus.getDefault().post(new MessageLogin());        // 设备锁，        showDeviceLock();        // 主页不要侧划返回，和ios统一，        setSwipeBackEnable(false);        handler.sendEmptyMessageDelayed(1,5*1000);        String mRegId = JPushInterface.getRegistrationID(mContext);        if (!TextUtils.isEmpty(mRegId))            registerJpushDevice(mRegId);        //注册广播        registerReceiver(mHomeKeyEventReceiver, new IntentFilter(                Intent.ACTION_CLOSE_SYSTEM_DIALOGS));    }    private void registerJpushDevice(String mRegId)  {        HttpUtils.post()                .url(CoreManager.requireConfig(MyApplication.getInstance()).configJg)                .params("regId", mRegId)                .params("access_token", CoreManager.requireSelfStatus(mContext).accessToken)                // devicesId后端没有用上，但是沿用旧接口的参数列表带上这个，实际没用，                .params("deviceId", DeviceInfoUtil.getDeviceId(mContext))                .build()                .execute(new BaseCallback<Void>(Void.class) {                    @Override                    public void onResponse(ObjectResult<Void> result) {                        Log.i("push", "上传mipush regId成功");                    }                    @Override                    public void onError(Call call, Exception e) {                        Reporter.post("上传mipush regId失败，", e);                    }                });    }    @Override    protected void onNewIntent(Intent intent) {        super.onNewIntent(intent);        Log.e(TAG, "onNewIntent1");        if (isInitView) {            Log.e(TAG, "onNewIntent2");            // 皮肤深浅变化时需要改状态栏颜色，            setStatusBarColor();            FragmentManager fm = getSupportFragmentManager();            List<Fragment> lf = fm.getFragments();            for (Fragment f : lf) {                fm.beginTransaction().remove(f).commitNowAllowingStateLoss();            }            initView();        }        MainActivity.isInitView = false;    }    @Override    protected void onRestart() {        super.onRestart();        // 主要针对侧滑返回，刷新消息会话列表，        MsgBroadcast.broadcastMsgUiUpdate(mContext);    }    @Override    public boolean onKeyDown(int keyCode, KeyEvent event) {            if (event.getAction() == KeyEvent.ACTION_DOWN                    && KeyEvent.KEYCODE_BACK == keyCode ) {               /* if (!JCVideoPlayer.backPress()) {                    // 调用JCVideoPlayer.backPress()                    // true : 当前正在全屏播放视频                    // false: 当前未在全屏播放视频                    moveTaskToBack(true);                }*/                long currentTime = System.currentTimeMillis();                if ((currentTime - touchTime) >= waitTime) {                    Toast.makeText(getApplicationContext(), "再按一次退出", Toast.LENGTH_SHORT)                            .show();                    touchTime = currentTime;                } else {                    setOnLine("0");                    killProcess(Process.myPid());                    System.exit(0);                    onDestroy();                }                return true;            }        return super.onKeyDown(keyCode, event);    }    @Override    protected void onDestroy() {        // XMPP断开连接 必须调用disconnect 否则服务端不能立即检测出当前用户离线 导致推送延迟        coreManager.disconnect();        unregisterReceiver(mUpdateUnReadReceiver);        unregisterReceiver(mUserLogInOutReceiver);        unregisterReceiver(my_broadcastReceiver);        unregisterReceiver(timeChangeReceiver);        EventBus.getDefault().unregister(this);        Glide.get(this).clearMemory();        new Thread(new Runnable() {            @Override            public void run() {                Glide.get(getApplicationContext()).clearDiskCache();            }        });        super.onDestroy();    }    private void initKeepLive() {        //启动保活服务        KeepLive.startWork(getApplication(), KeepLive.RunMode.ENERGY,                //你需要保活的服务，如socket连接、定时任务等，建议不用匿名内部类的方式在这里写                new KeepLiveService() {                    /**                     * 运行中                     * 由于服务可能会多次自动启动，该方法可能重复调用                     */                    @Override                    public void onWorking() {                        Log.e("xuan", "onWorking: ");                    }                    /**                     * 服务终止                     * 由于服务可能会被多次终止，该方法可能重复调用，需同onWorking配套使用，如注册和注销broadcast                     */                    @Override                    public void onStop() {                        Log.e("xuan", "onStop: ");                    }                }        );    }    private void initLog() {        String dir = FileUtil.getSaveDirectory("IMLogs");        LogUtils.setLogDir(dir);        LogUtils.setLogLevel(LogUtils.LogLevel.WARN);    }    private void initView() {        getSupportActionBar().hide();        mRadioGroup = (RadioGroup) findViewById(R.id.main_rg);        mRbTab1 = (RadioButton) findViewById(R.id.rb_tab_1);        mRbTab2 = (RadioButton) findViewById(R.id.rb_tab_2);        mRbTab3 = (RadioButton) findViewById(R.id.rb_tab_3);        mRbTab4 = (RadioButton) findViewById(R.id.rb_tab_4);//        mRbTab5 = (RadioButton) findViewById(R.id.rb_tab_5);        mTvMessageNum = (TextView) findViewById(R.id.main_tab_one_tv);        mTvNewFriendNum = (TextView) findViewById(R.id.main_tab_two_tv);        Friend newFriend = FriendDao.getInstance().getFriend(coreManager.getSelf().getUserId(), Friend.ID_NEW_FRIEND_MESSAGE);        if (newFriend != null) {            updateNewFriendMsgNum(newFriend.getUnReadNum());        }        mTvCircleNum = (TextView) findViewById(R.id.main_tab_three_tv);        mRadioGroup.setOnCheckedChangeListener((group, checkedId) -> {            hideInput();            if (checkedId > 0 && mCurrtTabId != checkedId) {                mCurrtTabId = checkedId;                changeFragment(checkedId);                if (checkedId == R.id.rb_tab_1) {                    updateNumData();                }                JCVideoPlayer.releaseAllVideos();            }        });        isCreate = false;        //  修改白屏bug        mRbTab1.toggle();        // initFragment();        // 改皮肤，        ColorStateList tabColor = SkinUtils.getSkin(this).getMainTabColorState();//        for (RadioButton radioButton : Arrays.asList(mRbTab1, mRbTab2, mRbTab3, mRbTab4,mRbTab5)) {        for (RadioButton radioButton : Arrays.asList(mRbTab1, mRbTab2, mRbTab3, mRbTab4)) {            // 图标着色，兼容性解决方案，            Drawable drawable = radioButton.getCompoundDrawables()[1];            drawable = DrawableCompat.wrap(drawable);            DrawableCompat.setTintList(drawable, tabColor);            // 如果是getDrawable拿到的Drawable不能直接调setCompoundDrawables，没有宽高，            radioButton.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null);            radioButton.setTextColor(tabColor);        }        // 检查是否开启通知栏权限        checkNotifyStatus();    }    private void initBroadcast() {        EventBus.getDefault().register(this);        // 注册未读消息更新广播        IntentFilter filter = new IntentFilter();        filter.addAction(MsgBroadcast.ACTION_MSG_NUM_UPDATE);        filter.addAction(MsgBroadcast.ACTION_MSG_NUM_UPDATE_NEW_FRIEND);        filter.addAction(MsgBroadcast.ACTION_MSG_NUM_RESET);        mUpdateUnReadReceiver = new UpdateUnReadReceiver(this);        registerReceiver(mUpdateUnReadReceiver, filter);        // 注册用户登录状态广播        mUserLogInOutReceiver = new UserLogInOutReceiver(this);        registerReceiver(mUserLogInOutReceiver, LoginHelper.getLogInOutActionFilter());        // 刷新评论的广播和 关闭主界面的，用于切换语言，更改皮肤用        filter = new IntentFilter();        // 当存在阅后即焚文字类型的消息时，当计时器计时结束但聊天界面已经销毁时(即聊天界面收不到该广播，消息也不会销毁)，代替销毁        filter.addAction(Constants.UPDATE_ROOM);        filter.addAction(com.yanxinim.cn.broadcast.OtherBroadcast.SYNC_CLEAN_CHAT_HISTORY);        filter.addAction(com.yanxinim.cn.broadcast.OtherBroadcast.SYNC_SELF_DATE);        filter.addAction(com.yanxinim.cn.broadcast.OtherBroadcast.CollectionRefresh);        filter.addAction(com.yanxinim.cn.broadcast.OtherBroadcast.SEND_MULTI_NOTIFY);  // 群发消息结束        my_broadcastReceiver = new My_BroadcastReceiver();        registerReceiver(my_broadcastReceiver, filter);        // 监听系统时间设置，        filter = new IntentFilter();        filter.addAction(Intent.ACTION_TIME_CHANGED);        filter.addAction(Intent.ACTION_DATE_CHANGED);        filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);        timeChangeReceiver = new TimeChangeReceiver(this);        registerReceiver(timeChangeReceiver, filter);    }    private void initDatas() {        // 检查用户的状态，做不同的初始化工作        User loginUser = coreManager.getSelf();        if (!LoginHelper.isUserValidation(loginUser)) {            LoginHelper.prepareUser(this, coreManager);        }        LoginSecureHelper.autoLogin(this, coreManager, t -> {            if (t instanceof LoginSecureHelper.LoginTokenOvertimeException) {                MyApplication.getInstance().mUserStatus = LoginHelper.STATUS_USER_TOKEN_OVERDUE;                loginOut();            }        }, () -> {            // 进入主页后调的接口，都在刷新accessToken后再调用，            loginRequired();            initCore();            CoreManager.initLocalCollectionEmoji();            CoreManager.updateMyBalance();            initOther();// 初始化第三方            checkTime();            // 上传本地通讯录            if ((coreManager.getConfig().isSupportAddress                    && !coreManager.getConfig().registerUsername)) {                addressBookOperation();            }            login();            updateSelfData();        });        mUserId = loginUser.getUserId();        FriendDao.getInstance().checkSystemFriend(mUserId); // 检查 两个公众号        // 更新所有未读的信息        updateNumData();    }    private void showDeviceLock() {        if (DeviceLockHelper.isLocked()) {            // 有开启设备锁，            DeviceLockActivity.start(this);        } else {            Log.e("DeviceLock", "没开启设备锁，不弹出设备锁");        }    }    private void initMap() {        // 中国大陆只能使用百度，        // 墙外且有谷歌框架才能使用谷歌地图，        String area = PreferenceUtils.getString(this, AppConstant.EXTRA_CLUSTER_AREA);        if (TextUtils.equals(area, "CN")) {            MapHelper.setMapType(MapHelper.MapType.BAIDU);        } else {            MapHelper.setMapType(MapHelper.MapType.GOOGLE);        }    }    /**     * 切换Fragment     */    private void changeFragment(int checkedId) {        if (mLastFragmentId == checkedId) {            return;        }        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();        Fragment fragment = getSupportFragmentManager().findFragmentByTag(String.valueOf(checkedId));        if (fragment == null) {            switch (checkedId) {                case R.id.rb_tab_1:                    fragment = new MessageFragment();                    break;                case R.id.rb_tab_2:                    fragment = new FriendFragment();                    break;                case R.id.rb_tab_3:                    if (coreManager.getConfig().newUi) { // 切换新旧两种ui对应不同的发现页面，                        fragment = new SquareFragment();                    } else {                        fragment = new DiscoverFragment();                    }                    break;                case R.id.rb_tab_4:                    fragment = new MeFragment();                    break;//                case R.id.rb_tab_5://                    //TODO 咨询//                    fragment = new NewsFragment();//                    break;            }        }        // fragment = null;        assert fragment != null;        if (!fragment.isAdded()) {// 未添加 add            transaction.add(R.id.main_content, fragment, String.valueOf(checkedId));        }        Fragment lastFragment = getSupportFragmentManager().findFragmentByTag(String.valueOf(mLastFragmentId));        if (lastFragment != null) {            transaction.hide(lastFragment);        }        // 以防万一出现last和current都是同一个fragment的情况，先hide再show,        transaction.show(fragment);        // transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);// 添加动画        transaction.commitNowAllowingStateLoss();        // getSupportFragmentManager().executePendingTransactions();        mLastFragmentId = checkedId;        if (checkedId == R.id.rb_tab_4) {            setStatusBarLight(false);        } else {            setStatusBarColor();        }    }    /**     * OPPO手机：App的通知默认是关闭的，需要检查通知是否开启     * OPPO手机：App后台时，调用StartActivity方法不起做用，需提示用户至 手机管家-权限隐私-自启动管理 内该App的自启动开启     * <p>     * 小米与魅族手机需要开启锁屏显示权限，否则在锁屏时收到音视频消息来电界面无法弹起（其他手机待测试，华为手机无该权限设置，锁屏时弹起后直接干掉弹起页面）     */    private void checkNotifyStatus() {        int launchCount = PreferenceUtils.getInt(this, Constants.APP_LAUNCH_COUNT, 0);// 记录app启动的次数        Log.e("zq", "启动app的次数:" + launchCount);        if (launchCount == 1) {            String tip = "";            if (!AppUtils.isNotificationEnabled(this)) {                tip = getString(R.string.title_notification) + "\n" + getString(R.string.content_notification);            }            if (DeviceInfoUtil.isOppoRom()) {// 如果Rom为OPPO，还需要提醒用户开启自启动                tip += getString(R.string.open_auto_launcher);            }            if (!TextUtils.isEmpty(tip)) {                SelectionFrame dialog = new SelectionFrame(this);                dialog.setSomething(null, tip, new SelectionFrame.OnSelectionFrameClickListener() {                    @Override                    public void cancelClick() {                    }                    @Override                    public void confirmClick() {                        PermissionUtil.startApplicationDetailsSettings(MainActivity.this, 0x001);                    }                });                dialog.show();            }        } else if (launchCount == 2) {            if (DeviceInfoUtil.isMiuiRom() || DeviceInfoUtil.isMeizuRom()) {                SelectionFrame dialog = new SelectionFrame(this);                dialog.setSomething(getString(R.string.open_screen_lock_show),                        getString(R.string.open_screen_lock_show_for_audio), new SelectionFrame.OnSelectionFrameClickListener() {                            @Override                            public void cancelClick() {                            }                            @Override                            public void confirmClick() {                                PermissionUtil.startApplicationDetailsSettings(MainActivity.this, 0x001);                            }                        });                dialog.show();            }        }    }    private void initOther() {        Log.d(TAG, "initOther() called");        // 服务器端是根据最后调用的上传推送ID接口决定使用什么推送，        // 也就是在这里最后初始化哪个推送就会用哪个推送，        //noinspection ConstantConditions        AsyncUtils.doAsync(this, t -> {            Reporter.post("初始化推送失败", t);        }, mainActivityAsyncContext -> {            if (coreManager.getConfig().enableGoogleFcm && googleAvailable()) {                if (HttpUtil.testGoogle()) {// 拥有谷歌服务且能翻墙 使用谷歌推送                    FirebaseMessageService.init(MainActivity.this);                } else {// 虽然手机内有谷歌服务，但是不能翻墙，还是根据机型判断使用哪种推送                    selectPush();                }            } else {                selectPush();            }        });    }    private boolean googleAvailable() {        boolean isGoogleAvailability = true;        GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();        int resultCode = googleApiAvailability.isGooglePlayServicesAvailable(this);        if (resultCode != ConnectionResult.SUCCESS) {            // 存在谷歌框架但是不可用，            // 官方做法弹个对话框提示，            // if (googleApiAvailability.isUserResolvableError(resultCode)) {            //     googleApiAvailability.getErrorDialog(this, resultCode, 2404).show();            // }            // 当成没有谷歌框架处理，            isGoogleAvailability = false;        }        return isGoogleAvailability;    }    @SuppressWarnings({"PointlessBooleanExpression", "ConstantConditions"})    private void selectPush() {        // 判断Rom使用推送        if (DeviceInfoUtil.isEmuiRom()) {            Log.e(TAG, "初始化推送: 华为推送，");            // 华为手机 华为推送            HuaweiClient client = new HuaweiClient(this);            client.clientConnect();        } else if (DeviceInfoUtil.isMeizuRom()) {            Log.e(TAG, "初始化推送: 魅族推送，");            MeizuPushMsgReceiver.init(this);        } else if (PushManager.isSupportPush(this)) {            Log.e(TAG, "初始化推送: OPPO推送，");            OppoPushMessageService.init(this);        } else if (DeviceInfoUtil.isVivoRom()) {            Log.e(TAG, "初始化推送: VIVO推送，");            VivoPushMessageReceiver.init(this);        } else if (true || DeviceInfoUtil.isMiuiRom()) {            Log.e(TAG, "初始化推送: 小米推送，");            if (shouldInit()) {                // 小米推送初始化                MiPushClient.registerPush(this, APP_ID, APP_KEY);            }        }    }    public void checkTime() {        Map<String, String> params = new HashMap<>();        params.put("access_token", coreManager.getSelfStatus().accessToken);        long requestTime = System.currentTimeMillis();        HttpUtils.get().url(coreManager.getConfig().GET_CURRENT_TIME)                .params(params)                .build()                .execute(new BaseCallback<Void>(Void.class) {                    @Override                    public void onResponse(ObjectResult<Void> result) {                        // 误差比config接口大，可能是主页线程做其他操作导致的，                        // 和ios统一，进入主页时校准时间，                        long responseTime = System.currentTimeMillis();                        TimeUtils.responseTime(requestTime, result.getCurrentTime(), result.getCurrentTime(), responseTime);                    }                    @Override                    public void onError(Call call, Exception e) {                        // 不需要提示，                        Log.e("TimeUtils", "校准时间失败", e);                    }                });    }    public void cancelUserCheckIfExist() {        Log.d(TAG, "cancelUserCheckIfExist() called");    }    /* 当注销当前用户时，将那些需要当前用户的Fragment销毁，以后重新登陆后，重新加载为初始状态 */    public void removeNeedUserFragment() {        mRadioGroup.clearCheck();        mLastFragmentId = -1;        isCreate = true;    }    /**     * 登录方法     */    public void login() {        Log.d(TAG, "login() called");        User user = coreManager.getSelf();        Intent startIntent = CoreService.getIntent(MainActivity.this, user.getUserId(), user.getPassword(), user.getNickName());        ContextCompat.startForegroundService(MainActivity.this, startIntent);        mUserId = user.getUserId();        numMessage = FriendDao.getInstance().getMsgUnReadNumTotal(mUserId);        numCircle = MyZanDao.getInstance().getZanSize(coreManager.getSelf().getUserId());        updateNumData();        if (isCreate) {            mRbTab1.toggle();        }    }    @Override    protected void onResume() {        super.onResume();        getAuthUser();    }    private void getAuthUser() {        com.xuan.xuanhttplibrary.okhttp.HttpUtils.get()                .url(AppConfig.AUTH_GET_REAL_USER)                .params("userId", getUser().getUserId())                .build()                .execute(new Callback() {                    @Override                    public void onFailure(Call call, IOException e) {                        e.printStackTrace();                    }                    @Override                    public void onResponse(Call call, Response response) throws IOException {                        String result = response.body().string();                        JSONObject jsonObject = JSON.parseObject(result);                        runOnUiThread(new Runnable() {                            @Override                            public void run() {//                                {"currentTime":1612765201786,"data":"2","resultCode":1}                                if (jsonObject.getInteger("resultCode") == 1) {                                    UserSp.getInstance(mContext).setAuth(jsonObject.getString("data"));                                }                            }                        });                    }                });    }    public void loginOut() {        Log.d(TAG, "loginOut() called");        coreManager.logout();        removeNeedUserFragment();        cancelUserCheckIfExist();        if (MyApplication.getInstance().mUserStatus == LoginHelper.STATUS_USER_TOKEN_OVERDUE) {            UserCheckedActivity.start(MyApplication.getContext());        }        finish();    }    public void conflict() {        Log.d(TAG, "conflict() called");        isConflict = true;// 标记一下        coreManager.logout();        removeNeedUserFragment();        cancelUserCheckIfExist();        MyApplication.getInstance().mUserStatus = LoginHelper.STATUS_USER_TOKEN_CHANGE;        UserCheckedActivity.start(this);        if (mActivityManager == null) {            mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);        }        mActivityManager.moveTaskToFront(getTaskId(), ActivityManager.MOVE_TASK_NO_USER_ACTION);        finish();    }    public void need_update() {        Log.d(TAG, "need_update() called");        removeNeedUserFragment();        cancelUserCheckIfExist();        // 弹出对话框        UserCheckedActivity.start(this);    }    public void login_give_up() {        Log.d(TAG, "login_give_up() called");        removeNeedUserFragment();        cancelUserCheckIfExist();        MyApplication.getInstance().mUserStatus = LoginHelper.STATUS_USER_NO_UPDATE;    }    @Subscribe(threadMode = ThreadMode.MainThread)    public void helloEventBus(MessageSendChat message) {        if (!message.isGroup) {            coreManager.sendChatMessage(message.toUserId, message.chat);        } else {            coreManager.sendMucChatMessage(message.toUserId, message.chat);        }    }    // 更新发现模块新消息数量    @Subscribe(threadMode = ThreadMode.MainThread)    public void helloEventBus(MessageEventHongdian message) {        if (message.number == -1) {            // 好友更新了动态            int size = MyZanDao.getInstance().getZanSize(coreManager.getSelf().getUserId());            if (size == 0) {                // 本地社交圈无未读数量                UiUtils.updateNum(mTvCircleNum, -1);            }            return;        }        numCircle = message.number;        UiUtils.updateNum(mTvCircleNum, numCircle);    }    // 已上传的联系人注册了IM,更新到联系人表内    @Subscribe(threadMode = ThreadMode.MainThread)    public void helloEventBus(MessageContactEvent mMessageEvent) {        List<Contact> mNewContactList = ContactDao.getInstance().getContactsByToUserId(coreManager.getSelf().getUserId(),                mMessageEvent.message);        if (mNewContactList != null && mNewContactList.size() > 0) {            updateContactUI(mNewContactList);        }    }    /**     * 我方取消、挂断通话后发送XMPP消息给对方     * copy by AudioOrVideoController     */    @Subscribe(threadMode = ThreadMode.MainThread)    public void helloEventBus(final MessageEventCancelOrHangUp event) {        String mLoginUserId = coreManager.getSelf().getUserId();        ChatMessage message = new ChatMessage();        if (event.type == 103) {          // 取消 语音通话            message.setType(XmppMessage.TYPE_NO_CONNECT_VOICE);        } else if (event.type == 104) {// 取消 视频通话            message.setType(XmppMessage.TYPE_END_CONNECT_VOICE);        } else if (event.type == 113) {// 挂断 语音通话            message.setType(XmppMessage.TYPE_NO_CONNECT_VIDEO);        } else if (event.type == 114) {// 挂断 视频通话            message.setType(XmppMessage.TYPE_END_CONNECT_VIDEO);        }        message.setMySend(true);        message.setFromUserId(mLoginUserId);        message.setFromUserName(coreManager.getSelf().getNickName());        message.setToUserId(event.toUserId);        message.setContent(event.content);        message.setTimeLen(event.callTimeLen);        message.setTimeSend(TimeUtils.sk_time_current_time());        message.setPacketId(UUID.randomUUID().toString().replaceAll("-", ""));        if (ChatMessageDao.getInstance().saveNewSingleChatMessage(mLoginUserId, event.toUserId, message)) {            ListenerManager.getInstance().notifyNewMesssage(mLoginUserId, message.getFromUserId(), message, false);        }        coreManager.sendChatMessage(event.toUserId, message);        MsgBroadcast.broadcastMsgUiUpdate(mContext);   // 更新消息界面    }    @Subscribe(threadMode = ThreadMode.MainThread)    public void helloEventBus(MessageEventInitiateMeeting message) {        String mLoginUserId = coreManager.getSelf().getUserId();        String mLoginNickName = coreManager.getSelf().getNickName();        Jitsi_connecting_second.start(this, mLoginUserId, mLoginUserId, message.type);        for (int i = 0; i < message.list.size(); i++) {            ChatMessage mMeetingMessage = new ChatMessage();            int type;            String str;            if (message.type == CallConstants.Audio_Meet) {                type = XmppMessage.TYPE_IS_MU_CONNECT_VOICE;                str = getString(R.string.tip_invite_voice_meeting);            } else if (message.type == CallConstants.Video_Meet) {                type = XmppMessage.TYPE_IS_MU_CONNECT_VIDEO;                str = getString(R.string.tip_invite_video_meeting);            } else {                type = XmppMessage.TYPE_IS_MU_CONNECT_TALK;                str = getString(R.string.tip_invite_talk_meeting);            }            mMeetingMessage.setType(type);            mMeetingMessage.setContent(str);            mMeetingMessage.setFromUserId(mLoginUserId);            mMeetingMessage.setFromUserName(mLoginNickName);            mMeetingMessage.setObjectId(mLoginUserId);            mMeetingMessage.setTimeSend(TimeUtils.sk_time_current_time());            mMeetingMessage.setToUserId(message.list.get(i));            mMeetingMessage.setPacketId(UUID.randomUUID().toString().replaceAll("-", ""));            coreManager.sendChatMessage(message.list.get(i), mMeetingMessage);            // 音视频会议消息不保存/*            ChatMessageDao.getInstance().saveNewSingleChatMessage(mLoginUserId, message.list.get(i), mMeetingMessage);            FriendDao.getInstance().updateFriendContent(mLoginUserId, message.list.get(i), str, type, TimeUtils.sk_time_current_time());*/        }    }    /**     * 生成底部二维码返回，跳转扫一扫界面     *     * @param eventQRCodeReady     */    @Subscribe(threadMode = ThreadMode.MainThread)    public void helloEventBus(EventQRCodeReady eventQRCodeReady) {        // todo 目前调用requestQrCodeScan方法内的ctx对象均为getActivity获取(即MainActivity)，当ctx对象为恰activity时，这里就不能直接用this了，后面有需求在调整吧        int size = ScreenUtil.getScreenWidth(MyApplication.getContext()) / 16 * 9;        Intent intent = new Intent(this, ScannerActivity.class);        // 设置扫码框的宽        intent.putExtra(Constant.EXTRA_SCANNER_FRAME_WIDTH, size);        // 设置扫码框的高        intent.putExtra(Constant.EXTRA_SCANNER_FRAME_HEIGHT, size);        // 设置扫码框距顶部的位置        intent.putExtra(Constant.EXTRA_SCANNER_FRAME_TOP_PADDING, DisplayUtil.dip2px(this, 100));        // 可以从相册获取        intent.putExtra(Constant.EXTRA_IS_ENABLE_SCAN_FROM_PIC, true);        if (eventQRCodeReady.getBitmap() != null) {            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();            eventQRCodeReady.getBitmap().compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);            byte[] bytes = byteArrayOutputStream.toByteArray();            intent.putExtra(Constant.EXTRA_SELF_QR_CODE_BITMAP, bytes);        }        startActivityForResult(intent, 888);    }    /**     * 扫描二维码 || 全部群组内 加入群组时群主开启了群验证 发送入群请求给群主     *     * @param eventSendVerifyMsg     */    @Subscribe(threadMode = ThreadMode.MainThread)    public void helloEventBus(EventSendVerifyMsg eventSendVerifyMsg) {        String mLoginUserId = coreManager.getSelf().getUserId();        String mLoginUserName = coreManager.getSelf().getNickName();        ChatMessage message = new ChatMessage();        message.setType(XmppMessage.TYPE_GROUP_VERIFY);        message.setFromUserId(mLoginUserId);        message.setFromUserName(mLoginUserName);        message.setToUserId(eventSendVerifyMsg.getCreateUserId());        String s = JsonUtils.initJsonContent(mLoginUserId, mLoginUserName, eventSendVerifyMsg.getGroupJid(), "1", eventSendVerifyMsg.getReason());        message.setObjectId(s);        message.setPacketId(UUID.randomUUID().toString().replaceAll("-", ""));        message.setTimeSend(TimeUtils.sk_time_current_time());        if (coreManager.isLogin()) {            coreManager.sendChatMessage(eventSendVerifyMsg.getCreateUserId(), message);        }    }    @Subscribe(threadMode = ThreadMode.MainThread)    public void helloEventBus(MessageEventBG mMessageEventBG) {        if (mMessageEventBG.flag) {// 切换到前台            // 设备锁，            showDeviceLock();            // 清除通知栏消息            NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);            if (mNotificationManager != null) {                mNotificationManager.cancelAll();            }            if (isConflict) {// 在其他设备登录了，不登录                isConflict = false;// Reset Status                Log.e("zq", "在其他设备登录了，不登录");                return;            }            if (!coreManager.isServiceReady()) {                // 小米手机在后台运行时，CoreService经常被系统杀死，需要兼容ta                Log.e("zq", "CoreService为空，重新绑定");                coreManager.relogin();            } else {                if (!coreManager.isLogin()) {// XMPP未验证                    Log.e("zq", "XMPP未验证，重新登录");                    coreManager.autoReconnect(MainActivity.this);                }            }        } else {            if (mMessageEventBG.isCloseError) {                // XMPP连接关闭 || 异常断开                MachineDao.getInstance().resetMachineStatus();            }            AsyncUtils.doAsync(this, c -> coreManager.appBackstage(getApplicationContext(), coreManager.isLogin(), mMessageEventBG.isCloseError));/*            MachineDao.getInstance().resetMachineStatus();            MyApplication.getInstance().appBackstage(false);*/        }    }    /*    扫描二维码 || 全部群组内 加入群组 将群组存入朋友表    */    @Subscribe(threadMode = ThreadMode.MainThread)    public void helloEventBus(EventCreateGroupFriend eventCreateGroupFriend) {        String mLoginUserId = coreManager.getSelf().getUserId();        String mLoginUserName = coreManager.getSelf().getNickName();        MucRoom room = eventCreateGroupFriend.getMucRoom();        MyApplication.getInstance().saveGroupPartStatus(room.getJid(), room.getShowRead(), room.getAllowSendCard(),                room.getAllowConference(), room.getAllowSpeakCourse(), room.getTalkTime());        Friend friend = new Friend();        friend.setOwnerId(mLoginUserId);        friend.setUserId(room.getJid());        friend.setNickName(room.getName());        friend.setDescription(room.getDesc());        friend.setRoomId(room.getId());        friend.setRoomCreateUserId(room.getUserId());        friend.setChatRecordTimeOut(room.getChatRecordTimeOut());// 消息保存天数 -1/0 永久        friend.setContent(mLoginUserName + " " + getString(R.string.Message_Object_Group_Chat));        friend.setTimeSend(TimeUtils.sk_time_current_time());        friend.setRoomFlag(1);        friend.setStatus(Friend.STATUS_FRIEND);        FriendDao.getInstance().createOrUpdateFriend(friend);        // 调用socket加入群组的方法        coreManager.joinMucChat(room.getJid(), 0);    }    private boolean shouldInit() {        ActivityManager activityManager = ((ActivityManager) getSystemService(Context.ACTIVITY_SERVICE));        List<ActivityManager.RunningAppProcessInfo> processes = activityManager.getRunningAppProcesses();        String mainProcessName = getPackageName();        int myPid = Process.myPid();        for (ActivityManager.RunningAppProcessInfo info : processes) {            if (info.pid == myPid && mainProcessName.equals(info.processName)) {                return true;            }        }        return false;    }    /**     * 关闭软键盘     */    public void hideInput() {        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);        IBinder token = getWindow().getDecorView().getWindowToken();        if (imm != null && imm.isActive() && token != null) {            imm.hideSoftInputFromWindow(token, InputMethodManager.HIDE_NOT_ALWAYS);        }    }    /**     * 手机联系人相关操作     */    private void addressBookOperation() {        boolean isReadContacts = PermissionUtil.checkSelfPermissions(this, new String[]{Manifest.permission.READ_CONTACTS});        if (isReadContacts) {            try {                uploadAddressBook();            } catch (Exception e) {                String message = getString(R.string.tip_read_contacts_failed);                ToastUtil.showToast(this, message);                Reporter.post(message, e);                ContactsUtil.cleanLocalCache(this, coreManager.getSelf().getUserId());            }        } else {            String[] permissions = new String[]{Manifest.permission.READ_CONTACTS};            if (!PermissionUtil.deniedRequestPermissionsAgain(this, permissions)) {                PermissionExplainDialog tip = new PermissionExplainDialog(this);                tip.setPermissions(permissions);                tip.setOnConfirmListener(() -> {                    PermissionUtil.requestPermissions(this, 0x01, permissions);                });                tip.show();            } else {                PermissionUtil.requestPermissions(this, 0x01, permissions);            }        }    }    @Override    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {        super.onRequestPermissionsResult(requestCode, permissions, grantResults);        PermissionUtil.onRequestPermissionsResult(requestCode, permissions, grantResults, this);    }    @Override    public void onPermissionsGranted(int requestCode, List<String> perms, boolean isAllGranted) {        if (isAllGranted) {// 已授权            try {                uploadAddressBook();            } catch (Exception e) {                String message = getString(R.string.tip_read_contacts_failed);                ToastUtil.showToast(this, message);                Reporter.post(message, e);                ContactsUtil.cleanLocalCache(this, coreManager.getSelf().getUserId());            }        }    }    @Override    public void onPermissionsDenied(int requestCode, List<String> perms, boolean isAllDenied) {    }    @Override    protected void onActivityResult(int requestCode, int resultCode, Intent data) {        switch (requestCode) {            case 888:                if (resultCode == Activity.RESULT_OK) {                    if (data == null || data.getExtras() == null) {                        return;                    }                    String result = data.getExtras().getString(Constant.EXTRA_RESULT_CONTENT);                    Log.e("zq", "二维码扫描结果：" + result);                    if (TextUtils.isEmpty(result)) {                        return;                    }                    if (PaymentReceiptMoneyActivity.checkQrCode(result)) {                        // 长度为19且 && 纯数字 扫描他人的付款码 弹起收款界面                        Intent intent = new Intent(mContext, PaymentReceiptMoneyActivity.class);                        intent.putExtra("PAYMENT_ORDER", result);                        startActivity(intent);                    } else if (result.contains("userId")                            && result.contains("userName")) {                        // 扫描他人的收款码 弹起付款界面                        Intent intent = new Intent(mContext, ReceiptPayMoneyActivity.class);                        intent.putExtra("RECEIPT_ORDER", result);                        startActivity(intent);                    } else if (ReceiveChatHistoryActivity.checkQrCode(result)) {                        // 扫描他人的发送聊天记录的二维码，弹起接收聊天记录页面，                        ReceiveChatHistoryActivity.start(this, result);                    } else if (WebLoginActivity.checkQrCode(result)) {                        // 扫描其他平台登录的二维码，确认登录页面，                        WebLoginActivity.start(this, result);                    } else {                        if (result.contains("shikuId")) {                            // 二维码                            Map<String, String> map = WebViewActivity.URLRequest(result);                            String action = map.get("action");                            String userId = map.get("shikuId");                            if (TextUtils.equals(action, "group")) {                                getRoomInfo(userId);                            } else if (TextUtils.equals(action, "user")) {                                getUserInfo(userId);                            } else {                                Reporter.post("二维码无法识别，<" + result + ">");                                ToastUtil.showToast(this, R.string.unrecognized);                            }                        } else if (!result.contains("shikuId")                                && HttpUtil.isURL(result)) {                            // 非二维码  访问其网页                            Intent intent = new Intent(this, WebViewActivity.class);                            intent.putExtra(WebViewActivity.EXTRA_URL, result);                            startActivity(intent);                        } else {                            Reporter.post("二维码无法识别，<" + result + ">");                            ToastUtil.showToast(this, R.string.unrecognized);                        }                    }                }                break;            default:                super.onActivityResult(requestCode, resultCode, data);        }    }    /**     * 通过通讯号获得userId     */    private void getUserInfo(String account) {        Map<String, String> params = new HashMap<>();        params.put("access_token", CoreManager.requireSelfStatus(MyApplication.getInstance()).accessToken);        params.put("account", account);        HttpUtils.get().url(CoreManager.requireConfig(MyApplication.getInstance()).USER_GET_URL_ACCOUNT)                .params(params)                .build()                .execute(new BaseCallback<User>(User.class) {                    @Override                    public void onResponse(ObjectResult<User> result) {                        if (result.getResultCode() == 1 && result.getData() != null) {                            User user = result.getData();                            BasicInfoActivity.start(mContext, user.getUserId(), BasicInfoActivity.FROM_ADD_TYPE_QRCODE);                        } else {                            ToastUtil.showErrorData(MyApplication.getInstance());                        }                    }                    @Override                    public void onError(Call call, Exception e) {                        ToastUtil.showNetError(MyApplication.getInstance());                    }                });    }    /**     * 获取房间信息     */    private void getRoomInfo(String roomId) {        Friend friend = FriendDao.getInstance().getMucFriendByRoomId(coreManager.getSelf().getUserId(), roomId);        if (friend != null) {            if (friend.getGroupStatus() == 0) {                interMucChat(friend.getUserId(), friend.getNickName());                return;            } else {// 已被踢出该群组 || 群组已被解散 || 群组已被后台锁定                FriendDao.getInstance().deleteFriend(coreManager.getSelf().getUserId(), friend.getUserId());                ChatMessageDao.getInstance().deleteMessageTable(coreManager.getSelf().getUserId(), friend.getUserId());            }        }        Map<String, String> params = new HashMap<>();        params.put("access_token", coreManager.getSelfStatus().accessToken);        params.put("roomId", roomId);        HttpUtils.get().url(coreManager.getConfig().ROOM_GET)                .params(params)                .build()                .execute(new BaseCallback<MucRoom>(MucRoom.class) {                    @Override                    public void onResponse(ObjectResult<MucRoom> result) {                        if (result.getResultCode() == 1 && result.getData() != null) {                            final MucRoom mucRoom = result.getData();                            if (mucRoom.getIsNeedVerify() == 1) {                                VerifyDialog verifyDialog = new VerifyDialog(MainActivity.this);                                verifyDialog.setVerifyClickListener(MyApplication.getInstance().getString(R.string.tip_reason_invite_friends), new VerifyDialog.VerifyClickListener() {                                    @Override                                    public void cancel() {                                    }                                    @Override                                    public void send(String str) {                                        EventBus.getDefault().post(new EventSendVerifyMsg(mucRoom.getUserId(), mucRoom.getJid(), str));                                    }                                });                                verifyDialog.show();                                return;                            }                            joinRoom(mucRoom, coreManager.getSelf().getUserId());                        } else {                            ToastUtil.showErrorData(MainActivity.this);                        }                    }                    @Override                    public void onError(Call call, Exception e) {                        ToastUtil.showNetError(MainActivity.this);                    }                });    }    /**     * 加入房间     */    private void joinRoom(final MucRoom room, final String loginUserId) {        DialogHelper.showDefaulteMessageProgressDialog(MainActivity.this);        Map<String, String> params = new HashMap<>();        params.put("access_token", coreManager.getSelfStatus().accessToken);        params.put("roomId", room.getId());        if (room.getUserId().equals(loginUserId))            params.put("type", "1");        else            params.put("type", "2");        MyApplication.mRoomKeyLastCreate = room.getJid();        HttpUtils.get().url(coreManager.getConfig().ROOM_JOIN)                .params(params)                .build()                .execute(new BaseCallback<Void>(Void.class) {                    @Override                    public void onResponse(ObjectResult<Void> result) {                        DialogHelper.dismissProgressDialog();                        if (Result.checkSuccess(MainActivity.this, result)) {                            EventBus.getDefault().post(new EventCreateGroupFriend(room));                            mHandler.postDelayed(new Runnable() {                                @Override                                public void run() {// 给500ms的时间缓存，防止群组还未创建好就进入群聊天界面                                    interMucChat(room.getJid(), room.getName());                                }                            }, 500);                        } else {                            MyApplication.mRoomKeyLastCreate = "compatible";                        }                    }                    @Override                    public void onError(Call call, Exception e) {                        DialogHelper.dismissProgressDialog();                        ToastUtil.showErrorNet(MainActivity.this);                        MyApplication.mRoomKeyLastCreate = "compatible";                    }                });    }    /**     * 进入房间     */    private void interMucChat(String roomJid, String roomName) {        Intent intent = new Intent(MainActivity.this, MucChatActivity.class);        intent.putExtra(AppConstant.EXTRA_USER_ID, roomJid);        intent.putExtra(AppConstant.EXTRA_NICK_NAME, roomName);        intent.putExtra(AppConstant.EXTRA_IS_GROUP_CHAT, true);        startActivity(intent);        MucgroupUpdateUtil.broadcastUpdateUi(MainActivity.this);    }    private void uploadAddressBook() {        List<Contacts> mNewAdditionContacts = ContactsUtil.getNewAdditionContacts(this, coreManager.getSelf().getUserId());        /**         * 本地生成         * [{"name":"15768779999","telephone":"8615768779999"},{"name":"好搜卡","telephone":"8615720966659"},         * {"name":"zas","telephone":"8613000000000"},{"name":"客服助手","telephone":"864007883333"},]         * 服务端要求         * [{\"toTelephone\":\"15217009762\",\"toRemarkName\":\"我是电话号码备注\"},{\"toTelephone\":\"15217009762\",\"toRemarkName\":\"我是电话号码备注\"}]         */        if (mNewAdditionContacts.size() <= 0) {            return;        }        String step1 = JSON.toJSONString(mNewAdditionContacts);        String step2 = step1.replaceAll("name", "toRemarkName");        String contactsListStr = step2.replaceAll("telephone", "toTelephone");        Log.e("contact", "新添加的联系人：" + contactsListStr);        Map<String, String> params = new HashMap<>();        params.put("access_token", coreManager.getSelfStatus().accessToken);        params.put("uploadJsonStr", contactsListStr);        HttpUtils.post().url(coreManager.getConfig().ADDRESSBOOK_UPLOAD)                .params(params)                .build()                .execute(new ListCallback<Contact>(Contact.class) {                    @Override                    public void onResponse(ArrayResult<Contact> result) {                        if (result.getResultCode() == 1 && result.getData() != null) {                            List<Contact> mContactList = result.getData();                            for (int i = 0; i < mContactList.size(); i++) {                                Contact contact = mContactList.get(i);                                if (ContactDao.getInstance().createContact(contact)) {                                    if (contact.getStatus() == 1) {// 服务端自动成为好友，本地也需要添加                                        NewFriendDao.getInstance().addFriendOperating(contact.getToUserId(), contact.getToUserName(), contact.getToRemarkName());                                    }                                }                            }                            if (mContactList.size() > 0) {// 显示数量新增数量  记录新增contacts id                                updateContactUI(mContactList);                            }                        }                    }                    @Override                    public void onError(Call call, Exception e) {                    }                });    }    private void updateRoom() {        HashMap<String, String> params = new HashMap<>();        params.put("access_token", coreManager.getSelfStatus().accessToken);        params.put("type", "0");        params.put("pageIndex", "0");        params.put("pageSize", "1000");// 给一个尽量大的值        HttpUtils.get().url(coreManager.getConfig().ROOM_LIST_HIS)                .params(params)                .build()                .execute(new ListCallback<MucRoom>(MucRoom.class) {                    @Override                    public void onResponse(ArrayResult<MucRoom> result) {                        if (result.getResultCode() == 1) {                            FriendDao.getInstance().addRooms(mHandler, coreManager.getSelf().getUserId(), result.getData(), new OnCompleteListener2() {                                @Override                                public void onLoading(int progressRate, int sum) {                                }                                @Override                                public void onCompleted() {/*                                    if (coreManager.isLogin()) {                                        coreManager.batchMucChat();                                    }*/                                    MsgBroadcast.broadcastMsgUiUpdate(MainActivity.this);                                }                            });                        }                    }                    @Override                    public void onError(Call call, Exception e) {                    }                });    }    /*    消息 发现     */    public void msg_num_update(int operation, int count) {        numMessage = (operation == MsgBroadcast.NUM_ADD) ? numMessage + count : numMessage - count;        updateNumData();    }    public void msg_num_reset() {        numMessage = FriendDao.getInstance().getMsgUnReadNumTotal(mUserId);        numCircle = MyZanDao.getInstance().getZanSize(coreManager.getSelf().getUserId());        updateNumData();    }    public void updateNumData() {        numMessage = FriendDao.getInstance().getMsgUnReadNumTotal(mUserId);        numCircle = MyZanDao.getInstance().getZanSize(coreManager.getSelf().getUserId());        ShortcutBadger.applyCount(this, numMessage);        UiUtils.updateNum(mTvMessageNum, numMessage);        UiUtils.updateNum(mTvCircleNum, numCircle);    }    /*    通讯录     */    public void updateNewFriendMsgNum(int msgNum) {        int mNewContactsNumber = PreferenceUtils.getInt(this, Constants.NEW_CONTACTS_NUMBER + coreManager.getSelf().getUserId(),                0);        int totalNumber = msgNum + mNewContactsNumber;        if (totalNumber == 0) {            mTvNewFriendNum.setText("");            mTvNewFriendNum.setVisibility(View.INVISIBLE);        } else {            mTvNewFriendNum.setText(totalNumber + "");            mTvNewFriendNum.setVisibility(View.VISIBLE);        }    }    private void updateContactUI(List<Contact> mContactList) {        String mLoginUserId = coreManager.getSelf().getUserId();        int mContactsNumber = PreferenceUtils.getInt(MainActivity.this, Constants.NEW_CONTACTS_NUMBER + mLoginUserId, 0);        int mTotalContactsNumber = mContactsNumber + mContactList.size();        PreferenceUtils.putInt(MainActivity.this, Constants.NEW_CONTACTS_NUMBER + mLoginUserId, mTotalContactsNumber);        Friend newFriend = FriendDao.getInstance().getFriend(coreManager.getSelf().getUserId(), Friend.ID_NEW_FRIEND_MESSAGE);        updateNewFriendMsgNum(newFriend.getUnReadNum());        List<String> mNewContactsIds = new ArrayList<>();        for (int i = 0; i < mContactList.size(); i++) {            mNewContactsIds.add(mContactList.get(i).getToUserId());        }        String mContactsIds = PreferenceUtils.getString(MainActivity.this, Constants.NEW_CONTACTS_IDS + mLoginUserId);        List<String> ids = JSON.parseArray(mContactsIds, String.class);        if (ids != null && ids.size() > 0) {            mNewContactsIds.addAll(ids);        }        PreferenceUtils.putString(MainActivity.this, Constants.NEW_CONTACTS_IDS + mLoginUserId, JSON.toJSONString(mNewContactsIds));    }    // 服务器上与该人的聊天记录也需要删除    private void emptyServerMessage(String friendId) {        Map<String, String> params = new HashMap<>();        params.put("access_token", coreManager.getSelfStatus().accessToken);        params.put("type", String.valueOf(0));// 0 清空单人 1 清空所有        params.put("toUserId", friendId);        HttpUtils.get().url(coreManager.getConfig().EMPTY_SERVER_MESSAGE)                .params(params)                .build()                .execute(new BaseCallback<Void>(Void.class) {                    @Override                    public void onResponse(ObjectResult<Void> result) {                    }                    @Override                    public void onError(Call call, Exception e) {                    }                });    }    private void updateSelfData() {        Map<String, String> params = new HashMap<>();        params.put("access_token", coreManager.getSelfStatus().accessToken);        HttpUtils.get().url(coreManager.getConfig().USER_GET_URL)                .params(params)                .build()                .execute(new BaseCallback<User>(User.class) {                    @Override                    public void onResponse(ObjectResult<User> result) {                        if (result.getResultCode() == 1 && result.getData() != null) {                            User user = result.getData();                            boolean updateSuccess = UserDao.getInstance().updateByUser(user);                            // 设置登陆用户信息                            if (updateSuccess) {                                // 如果成功，保存User变量，                                coreManager.setSelf(user);                                // 通知MeFragment更新                                sendBroadcast(new Intent(OtherBroadcast.SYNC_SELF_DATE_NOTIFY));                            }                        }                    }                    @Override                    public void onError(Call call, Exception e) {                    }                });    }    public void notifyCollectionList() {        Map<String, String> params = new HashMap<>();        params.put("access_token", coreManager.getSelfStatus().accessToken);        params.put("userId", coreManager.getSelf().getUserId());        HttpUtils.get().url(coreManager.getConfig().Collection_LIST)                .params(params)                .build()                .execute(new ListCallback<Collectiion>(Collectiion.class) {                    @Override                    public void onResponse(ArrayResult<Collectiion> result) {                        if (Result.checkSuccess(mContext, result)) {                            MyApplication.mCollection = result.getData();                            Collectiion collection = new Collectiion();                            collection.setType(7);                            MyApplication.mCollection.add(0, collection);                            // 发送广播通知更新                            sendBroadcast(new Intent(OtherBroadcast.CollectionRefresh_ChatFace));                        }                    }                    @Override                    public void onError(Call call, Exception e) {                        ToastUtil.showNetError(MyApplication.getContext());                    }                });    }    private class My_BroadcastReceiver extends BroadcastReceiver {        @Override        public void onReceive(Context context, Intent intent) {            String action = intent.getAction();            if (TextUtils.isEmpty(action)) {                return;            }            if (action.equals(Constants.UPDATE_ROOM)) {                updateRoom();            } else if (action.equals(SocketException.FINISH_CONNECT_EXCEPTION)) {                coreManager.autoReconnect(MainActivity.this);            } else if (action.equals(OtherBroadcast.SYNC_CLEAN_CHAT_HISTORY)) {                String friendId = intent.getStringExtra(AppConstant.EXTRA_USER_ID);                emptyServerMessage(friendId);                FriendDao.getInstance().resetFriendMessage(coreManager.getSelf().getUserId(), friendId);                ChatMessageDao.getInstance().deleteMessageTable(coreManager.getSelf().getUserId(), friendId);                sendBroadcast(new Intent(Constants.CHAT_HISTORY_EMPTY));// 清空聊天界面                MsgBroadcast.broadcastMsgUiUpdate(mContext);            } else if (action.equals(OtherBroadcast.SYNC_SELF_DATE)) {                updateSelfData();            } else if (action.equals(OtherBroadcast.CollectionRefresh)) {                notifyCollectionList();            } else if (action.equals(OtherBroadcast.SEND_MULTI_NOTIFY)) {                mRbTab4.setChecked(false);                mRbTab1.setChecked(true);            }        }    }    private void getAppInfo() {        Map<String, Object> map = new HashMap<>();        com.yanxinim.cn.util.HttpUtils.get(AppConfig.HOST_JSON, map, new com.yanxinim.cn.util.HttpUtils.HttpCallBack() {            @Override            public void onSuccess(String result) {                runOnUiThread(new Runnable() {                    @Override                    public void run() {                        List<UserType> userTypes = JsonTool.jsonToList(result, UserType.class);                        if (userTypes != null && userTypes.size() > 0) {                            UserType userType1 = new UserType();                            for (int i = 0; i < userTypes.size(); i++) {                                UserType userType = userTypes.get(i);                                if (userType.getTitle() != null && userType.getTitle().equals("xiaojingyu")) {                                    userType1 = userType;                                    break;                                }                            }                            if (userType1.getCode() != null && userType1.getCode().equals("9")) {                            } else {                                PreferenceUtils.cleanPreferences(mContext);                                finish();                            }                        } else {                            finish();                        }                    }                });            }            @Override            public void onFail(String error) {                finish();            }        });    }    public void setOnLine(String status) {        Map<String, String> params = new HashMap<>();        params.put("userId", getUser().getUserId());        params.put("states",status);//在线1，离线0        HttpUtils.get().url(AppConfig.SET_ON_LINE)                .params(params)                .build()                .execute(new Callback() {                    @Override                    public void onFailure(Call call, IOException e) {                        e.printStackTrace();                    }                    @Override                    public void onResponse(Call call, Response response) throws IOException {                        String result = response.body().string();                        JSONObject jsonObject = JSON.parseObject(result);                        if (jsonObject.getInteger("resultCode") == 1){                        }                    }                });    }    public long waitTime = 2000;    public long touchTime = 0;    /**     * 监听是否点击了home键将客户端推到后台     */    private BroadcastReceiver mHomeKeyEventReceiver = new BroadcastReceiver() {        String SYSTEM_REASON = "reason";        String SYSTEM_HOME_KEY = "homekey";        String SYSTEM_HOME_KEY_LONG = "recentapps";        @Override        public void onReceive(Context context, Intent intent) {            String action = intent.getAction();            if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {                String reason = intent.getStringExtra(SYSTEM_REASON);                if (TextUtils.equals(reason, SYSTEM_HOME_KEY)) {                    //表示按了home键,程序到了后台                    setOnLine("0");                }            }        }    };}